/*
 *  POJ1836: Alignment
 */

/*-------- Includes --------*/
#include <iostream>
#include <algorithm>

using namespace std;

/*-------- Defines --------*/


/*-------- Types --------*/


/*-------- Global Variables --------*/
int   N;
float h[1000];

int dpl[1000];
int dpr[1000];

/*-------- Function Prototypes --------*/


/*-------- Main Function --------*/
int main(int argc, char const *argv[])
{
    // get input
    cin >> N;

    for (int i = 0; i < N; i++) cin >> h[i];

    // initialize
    for (int i = 0; i < N; i++) dpl[i] = dpr[i] = 1;

    // dp of LIS from left to right
    for (int i = 1; i < N; i++)
        for (int j = 0; j < i; j++)
            if (h[i] > h[j])
                dpl[i] = max(dpl[i], dpl[j] + 1);

    // dp of LIS from rigth to left
    for (int i = N - 2; i >= 0; i--)
        for (int j = N - 1; j > i; j--)
            if (h[i] > h[j])
                dpr[i] = max(dpr[i], dpr[j] + 1);

    // for (int i = 0; i < N; i++) cout << dpl[i] << '\t';
    // cout << endl;
    // for (int i = 0; i < N; i++) cout << dpr[i] << '\t';
    // cout << endl;

    int maxi = 0;
    for (int i = 0; i < N - 1; i++)
        maxi = max(maxi, dpl[i] + *max_element(dpr + i + 1, dpr + N));

    cout << N - maxi << endl;

    return 0;
}

/*-------- Functions --------*/

